<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(numbers) {
      var obj = {};//新建一个空对象来保存数组中数字出现的次数
      var len = numbers.length;
      numbers.forEach(function (s) {
        if (obj[s]) {//如果该数字出现过，则obj中以该数字为key的value加1
          obj[s]++;
        } else {//如果该数字出现过，则obj中以该数字为key的value加1
          obj[s] = 1;
        }
        console.log(obj[s])
      })
      for (var i in obj) {//如果该数字出现过，则obj中以该数字为key的value加1
        if (obj[i] > Math.floor(len / 2)) {
          return i;
        }
      }
      return -1;
    }
    console.log(arr([1, 2, 3]))
  </script>
</body>

</html>